import { LoveTaskBaseBody } from "./LoveTaskBaseBody";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../../scene/events/PlayerEvent";
import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { Language } from "../../../../extend/language/Language";
import { LoveTaskGiveFlowerItem } from "./gotoPanel/LoveTaskGiveFlowerItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { ObjCreate } from "../common/ObjCreate";
import { TaskProcessPanel } from "../task/imgtxt/TaskProcessPanel";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ESex } from "../../../../Message/Public/ESex";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class LoveTaskGoToPanel
    
    export  class LoveTaskGoToPanel extends LoveTaskBaseBody
    {
        constructor()
        {
            super();
            this._talkPlayer = new PlayerMiniInfo();
            return;
        }

        /* internal  */onTalkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, this.getTalkPlayer()));
            return;
        }

        /* internal  */getTalkPlayer(): PlayerMiniInfo
        {
            if (this._from) 
            {
                this._talkPlayer.miniPlayer = Cache.instance.loveTask.toPlayer;
            }
            else 
            {
                this._talkPlayer.miniPlayer = Cache.instance.loveTask.fromPlayer;
            }
            return this._talkPlayer;
        }

        /* internal  */onGoToBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._inDis) 
            {
                RolePlayer.instance.readyRest();
                loc1 = Cache.instance.loveTask.getTargetPlayer(!this._from);
                if (loc1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Rest_BeginDoubleRest, loc1.entityId));
                }
            }
            else 
            {
                gotoRandomPoint();
            }
            return;
        }

        /* internal  */onGridWalkEndHandler(arg1: PlayerEvent): void
        {
            var loc1=Cache.instance.loveTask.sceneEffectTarget;
            var loc2=GameMapUtil.getDistancePow(loc1.x, loc1.y, RolePlayer.instance.currentPoint.x, RolePlayer.instance.currentPoint.y);
            if (loc2 < 200) 
            {
                if (!this._inDis) 
                {
                    this._inDis = true;
                    this._gotoBtn.label = Language.getString(21214);
                }
            }
            else if (this._inDis) 
            {
                this._inDis = false;
                this._gotoBtn.label = Language.getString(21209);
            }
            return;
        }

        /* internal  */onLoveResLoadedHandler(): void
        {
            this._flower1 = new LoveTaskGiveFlowerItem();
            this._flower1.updateData(GlobalClass.getBitmap(ImagesConst.flower_1), HTMLUtil.addColor(Language.getStringByParam(21215, 1), ColorConfig.instance.getItemColorString(2)), 1);
            this._flower1.x = width / 2 - 190;
            this._flower1.y = 100;
            this._flower1.addEventListener(flash.events.MouseEvent.CLICK, this.onFlowerClickHandler);
            addChild(this._flower1);
            this._flower9 = new LoveTaskGiveFlowerItem();
            this._flower9.updateData(GlobalClass.getBitmap(ImagesConst.flower_9), HTMLUtil.addColor(Language.getStringByParam(21215, 99), ColorConfig.instance.getItemColorString(3)), 99);
            this._flower9.x = width / 2 - 45;
            this._flower9.y = this._flower1.y;
            this._flower9.addEventListener(flash.events.MouseEvent.CLICK, this.onFlowerClickHandler);
            addChild(this._flower9);
            this._flower99 = new LoveTaskGiveFlowerItem();
            this._flower99.updateData(GlobalClass.getBitmap(ImagesConst.flower_99), HTMLUtil.addColor(Language.getStringByParam(21215, 999), ColorConfig.instance.getItemColorString(4)), 999);
            this._flower99.x = width / 2 + 110;
            this._flower99.y = this._flower1.y;
            this._flower99.addEventListener(flash.events.MouseEvent.CLICK, this.onFlowerClickHandler);
            addChild(this._flower99);
            return;
        }

        /* internal  */onFlowerClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as LoveTaskGiveFlowerItem;
            var loc2=Cache.instance.loveTask.getTargetPlayerName(!this._from, false);
            Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerOpenHandselFlower, {"name": loc2, "num": loc1.num, "toPlayer": this.getTalkPlayer()}));
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _titleTxt = ObjCreate.createTextField("", 0, 0, width, 100, this, _textFormat);
            _titleTxt.wordWrap = true;
            _titleTxt.multiline = true;
            _titleTxt.addEventListener(flash.events.TextEvent.LINK, onTitleTxtLinkHandler);
            _bodyImg = new TaskProcessPanel();
            addChild(_bodyImg);
            this._talkBtn = ObjCreate.createGButton(Language.getString(21208), 0, 0, 74, 24, this, "ButtonGreenStyle");
            this._gotoBtn = ObjCreate.createGButton(Language.getString(21209), 0, 0, 74, 24, this, "ButtonGreenStyle");
            this._talkBtn.x = width / 2 - this._talkBtn.width - 20;
            this._talkBtn.y = this.height - 30;
            this._gotoBtn.x = width / 2 + 20;
            this._gotoBtn.y = this._talkBtn.y;
            this._talkBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTalkBtnClickHandler);
            this._gotoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToBtnClickHandler);
            this._flowerTxt = ObjCreate.createTextField(Language.getString(21216), _titleTxt.x, 75, width, 20, this);
            this._flowerTxt.textColor = 16776960;
            LoaderHelp.addResCallBack(ResFileConst.loveFlower, this.onLoveResLoadedHandler);
            return;
        }

        public /* override */ updatePanelType(arg1: Boolean): void
        {
            var loc1=null;
            super.updatePanelType(arg1);
            this._from = arg1;
            if (arg1) 
            {
                _titleTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(21206, Cache.instance.loveTask.targetStr, Cache.instance.loveTask.getTargetPlayerName(false, true)), "#F5BCBC");
            }
            else 
            {
                loc1 = Cache.instance.role.entityInfo.sex != ESex._ESexMan ? Language.getString(21204) : Language.getString(21205);
                _titleTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(21207, Cache.instance.loveTask.targetStr, Cache.instance.loveTask.getTargetPlayerName(true, true), loc1, loc1), "#F5BCBC");
            }
            if (Cache.instance.loveTask.isCrossLove) 
            {
                _titleTxt.y = 20;
            }
            else 
            {
                _titleTxt.htmlText = _titleTxt.htmlText + HTMLUtil.addColor(Language.getString(21213), "#00ff00");
                _titleTxt.y = 0;
            }
            _bodyImg.updateData(_titleTxt, null, false, onFlyGotoHandler, 1);
            RolePlayer.instance.addEventListener(PlayerEvent.GIRD_WALK_END, this.onGridWalkEndHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.WALK_END, this.onGridWalkEndHandler);
            this.onGridWalkEndHandler(null);
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            this._inDis = false;
            RolePlayer.instance.removeEventListener(PlayerEvent.GIRD_WALK_END, this.onGridWalkEndHandler);
            RolePlayer.instance.removeEventListener(PlayerEvent.WALK_END, this.onGridWalkEndHandler);
            return;
        }

        public /* override */ get bgH(): int
        {
            return 240;
        }

        public /* override */ get height(): number
        {
            return 170;
        }

        /* internal */ /* var */_talkBtn: GButton;

        /* internal */ /* var */_gotoBtn: GButton;

        /* internal */ /* var */_talkPlayer: PlayerMiniInfo;

        /* internal */ /* var */_from: Boolean;

        /* internal */ /* var */_inDis: Boolean;

        /* internal */ /* var */_flowerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_flower1: LoveTaskGiveFlowerItem;

        /* internal */ /* var */_flower9: LoveTaskGiveFlowerItem;

        /* internal */ /* var */_flower99: LoveTaskGiveFlowerItem;
    }
